#define _CRT_SECURE_NO_WARNINGS 1
#include<cstdio>
const int done = 1;
int arr[500] = { 9,5,7,6,5,2,7,1,12,9 };
int big_heap[500];
void swap(int x, int y)
{
	int box = big_heap[x];
	big_heap[x] = big_heap[y];
	big_heap[y] = box;
}
void down_to_up_heapify(int T)
{
	while (done)
	{
		if (T / 2 > 0)
		{
			if (big_heap[T] > big_heap[T / 2])
			{
				swap(T, T / 2);
				T /= 2;
			}
			else return;
		}
		else return;
	}
		
}
void up_to_down_heapify(int T)
{
	int happen = 0;
	int P = T;
	int box = big_heap[T];
	if (2 * T > big_heap[0])
	{
		return;
	}
	if (big_heap[T] < big_heap[2 * T])
	{
		box = big_heap[2 * T];
		swap(T, 2 * T);
		P = 2 * T;
		happen = done;
	}
	if (big_heap[0] >= 2 * T + 1 && box < big_heap[2 * T + 1])
	{
		swap(T, 2 * T + 1);
		if (happen != done)    P = 2 * T + 1;
	}
	up_to_down_heapify(P);
}
void insert(int value)
{
	big_heap[big_heap[0] + 1] = value;
	big_heap[0]++;
	down_to_up_heapify(big_heap[0] + 1);
}
void build_heap()
{
	for (int i = big_heap[0] / 2; i > 0; i--)
	{
		up_to_down_heapify(i);
	}
}
int main()
{
	int a = 0;
	scanf("%d", &a);
	for (int i = 1; i < arr[0] + 1; i++)
	{
		big_heap[i] = arr[i];
		big_heap[0]++;
	}
	build_heap();
	insert(a);
	down_to_up_heapify(big_heap[0]);
	for (int i = 1; i < big_heap[0] + 1; i++)
	{
		printf("%d ", big_heap[i]);
	}
	
	return 0;
}